#!/usr/bin/expect
#创建beetle机器ssh密钥

set timeout 1
set user [lindex $argv 0]
#开启子进程
spawn su ${user}
expect "*$*"
send "ssh-keygen -t rsa\r"
expect "*Enter*"
send "/usr/local/Beetle/ssh/id_rsa\r"
expect "*Enter*" {send "\r"}\
    "*Overwrite*" {send "n\r"}
expect "*Enter*"
send "\r"
expect "*$*"
send "cp /usr/local/Beetle/ssh/id_rsa /usr/local/Beetle/ssh/common_id_rsa\r"
expect {
    "*No such file*" { exit 1 }
}
#expect "*$*"
#send "exit"
#结束子进程
expect eof
exit